
attribute vec3		va_Tangent1;
attribute vec3		va_Tangent2;

uniform vec3		viewOrigin;
uniform vec3		lightOrigin;
uniform float		colorScale;
uniform float		colorBias;
uniform mat4		bumpMatrix;
uniform mat4		diffuseMatrix;
uniform mat4		specularMatrix;
uniform mat4		lightMatrix;

varying vec3		viewVector;
varying vec3		lightVector;
varying vec2		bumpTexCoord;
varying vec2		diffuseTexCoord;
varying vec2		specularTexCoord;
varying vec4		lightTexCoord;
varying vec4		vertexColor;


void main (void){

	vec3		viewVec, lightVec;

	// Position invariant
	gl_Position = ftransform();

	// Compute the view vector in tangent space
	viewVec = viewOrigin - gl_Vertex.xyz;

	viewVector.x = dot(viewVec, va_Tangent1.xyz);
	viewVector.y = dot(viewVec, va_Tangent2.xyz);
	viewVector.z = dot(viewVec, gl_Normal.xyz);

	// Compute the light vector in tangent space
	lightVec = lightOrigin - gl_Vertex.xyz;

	lightVector.x = dot(lightVec, va_Tangent1.xyz);
	lightVector.y = dot(lightVec, va_Tangent2.xyz);
	lightVector.z = dot(lightVec, gl_Normal.xyz);

	// Transform the bump map texcoord
	bumpTexCoord.s = dot(gl_MultiTexCoord0, bumpMatrix[0]);
	bumpTexCoord.t = dot(gl_MultiTexCoord0, bumpMatrix[1]);

	// Transform the diffuse map texcoord
	diffuseTexCoord.s = dot(gl_MultiTexCoord0, diffuseMatrix[0]);
	diffuseTexCoord.t = dot(gl_MultiTexCoord0, diffuseMatrix[1]);

	// Transform the specular map texcoord
	specularTexCoord.s = dot(gl_MultiTexCoord0, specularMatrix[0]);
	specularTexCoord.t = dot(gl_MultiTexCoord0, specularMatrix[1]);

	// Compute the light projection/falloff texcoord
	lightTexCoord.s = dot(gl_Vertex, lightMatrix[0]);
	lightTexCoord.t = dot(gl_Vertex, lightMatrix[1]);
	lightTexCoord.p = dot(gl_Vertex, lightMatrix[2]);
	lightTexCoord.q = dot(gl_Vertex, lightMatrix[3]);

	// Compute the vertex color
	vertexColor = gl_Color * colorScale + colorBias;
}
